import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/8 13:43
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int countServers(int[][] grid) {
        int m = grid.length, n = grid[0].length;
        int ans = 0;
        for (int i = 0; i < m; i++) {
            // 第i行服务器数
            int sum = 0;
            // 只有1台服务器下标
            int col = 0;
            for (int j = 0; j < n; j++) {
                sum += grid[i][j];
                if (grid[i][j] == 1) {
                    col = j;
                }
            }
            if (sum > 1) {
                // 说明在同一行有多台服务器
                ans += sum;
            }else if (sum == 1){
               for (int k = 0; k < m; k++) {
                   if (k != i && grid[k][col] == 1) {
                       // 同一列存在服务器
                       ans++;
                       break;
                   }
               }
            }
        }
        return ans;
    }
}
